package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.entity.ResponseResult;
import com.xdf.xzymanagementsystem.entity.SysRoleGroup;
import com.xdf.xzymanagementsystem.entity.SysUserRoleGroup;
import com.xdf.xzymanagementsystem.entity.UserContact;
import com.xdf.xzymanagementsystem.enums.ResponseEnum;
import com.xdf.xzymanagementsystem.service.UserContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chanchaw
 * @create 2022-08-24 16:17
 */
@Api(tags = "用户与客户的映射关系")
@CrossOrigin
@RestController
@RequestMapping("/usercontact")
public class UserContactController {
    @Autowired
    private UserContactService service;

    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "自动生成的新增方法")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResult<Integer> insert(UserContact record) throws Exception {
        Integer ret = service.insertSelective(record);
        return ResponseResult.<Integer>builder().success(true).data(ret).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "选择性修改", httpMethod = "POST", notes = "自动生成的新增方法")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResult<Integer> update(UserContact record) throws Exception {
        Integer ret = service.updateByPrimaryKeySelective(record);
        return ResponseResult.<Integer>builder().success(true).data(ret).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "根据主键删除方法", httpMethod = "DELETE", notes = "自动生成的删除方法")
    @RequestMapping(value = "/deleteByPk", method = RequestMethod.POST)
    public ResponseResult<Integer> deleteByPrimaryKey(@RequestParam("id") Integer id) throws Exception {
        Integer ret = service.deleteByPrimaryKey(id);
        return ResponseResult.<Integer>builder().success(true).data(ret).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "查询方法", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/listQuery", method = RequestMethod.GET)
    public List<UserContact> query(UserContact record) throws Exception {
        return service.selectByParam(record);
    }

    @ApiOperation(value = "根据主键查询", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/queryByPk/{id}", method = RequestMethod.GET)
    public UserContact selectByPrimaryKey(@PathVariable("id") Integer id) throws Exception {
        if (id == null) return null;
        return service.selectByPrimaryKey(id);
    }
}
